package com.wshl.cloudservice.activities;

import android.os.Bundle;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.LogUtils;
import com.wshl.cloudservice.R;
import com.wshl.cloudservice.adapter.MsgListAdapter;
import com.wshl.cloudservice.ui.widget.DragContainerLayout;
import com.wshl.cloudservice.ui.widget.DragFrameLayout;
import com.wshl.cloudservice.ui.widget.DragView;
import com.wshl.cloudservice.utils.SoftKeyBoardListener;
import com.wshl.cloudservice.utils.WindowUtil;

import java.util.ArrayList;
import java.util.List;

public class TestActivity extends BaseCallActivity {
    private DragFrameLayout mLayoutSmallView;
    private FrameLayout mLayoutBigView;

    private AppCompatImageView mMuteBtn;
    private AppCompatImageView mCameraBtn;
    private TextView tvTime;
    private TextView tvShow;
    private RelativeLayout rlBottom;
    private EditText etComment;
    private RecyclerView mRecycle;
    private TextView tvServerNIckname;
    private SoftKeyBoardListener softKeyBoardListener;
    private TextView tvSend;


    private MsgListAdapter mAdapter;
    private List<String> msgList = new ArrayList<>();
    private SurfaceView mSurface;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //使用键盘监听，必须要设置这两个属性
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

        //隐藏状态栏
        WindowUtil.hideWindowStatusBar(getWindow());
        setContentView(R.layout.activity_video);
        initUI();
    }

    private void initUI() {

        mLayoutSmallView = findViewById(R.id.local_preview_layout);
        mLayoutBigView = findViewById(R.id.remote_preview_layout);
        mCameraBtn = findViewById(R.id.btn_camera);
        mMuteBtn = findViewById(R.id.btn_mute);
        tvTime = findViewById(R.id.tv_time);
        tvShow = findViewById(R.id.tv_show);
        rlBottom = findViewById(R.id.rl_bottom);
        etComment = findViewById(R.id.et_msg);
        tvSend = findViewById(R.id.tv_send);
        tvServerNIckname = findViewById(R.id.tv_server_nickname);
        mRecycle = findViewById(R.id.recycle_msg);

        mSurface = new SurfaceView(this);
        mSurface.setBackgroundColor(getResources().getColor(R.color.colorAccent));
        mSurface.setZOrderOnTop(true);
        mLayoutSmallView.addView(mSurface);

        for (int i = 0; i < 20; i++) {
            msgList.add("hahhaahah" + i);
        }
        //设置聊天消息列表
        mRecycle.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new MsgListAdapter(this, msgList);
        mRecycle.setAdapter(mAdapter);

        //客服昵称
        tvServerNIckname.setText("DSDS");

        setSoftKeyBoardListener();
    }

    /**
     * 软键盘监听
     */
    private void setSoftKeyBoardListener() {
        softKeyBoardListener = new SoftKeyBoardListener(this);
        //软键盘状态监听
        softKeyBoardListener.setListener(new SoftKeyBoardListener.OnSoftKeyBoardChangeListener() {
            @Override
            public void keyBoardShow(int height) {

                //动态设置控件宽高
                ViewGroup.LayoutParams params = rlBottom.getLayoutParams();
                rlBottom.setPadding(0, 0, 0, height);
                rlBottom.setLayoutParams(params);
                //当软键盘显示的时候
                rlBottom.setVisibility(View.VISIBLE);
                tvShow.setVisibility(View.GONE);
                //tv_shape2.setVisibility(View.VISIBLE);

                etComment.requestFocus();
                etComment.setFocusable(true);
                etComment.setCursorVisible(true);
                etComment.setFocusableInTouchMode(true);

            }

            @Override
            public void keyBoardHide(int height) {

                //当软键盘隐藏的时候
                rlBottom.setVisibility(View.GONE);
                etComment.setText("");
                tvShow.setVisibility(View.VISIBLE);
            }
        });

    }

    public void onButtonClicked(View view) {

        if (view.getId() == R.id.local_preview_layout) {

            LogUtils.i("点击事件");
        }

    }
}
